package org.tulkas.config;

/**
 * @author <a href="mailto:tulkas.web@gmail.com">Tulkas</a>
 *
 */
public abstract class Configuration {
	public abstract String getValue(String key);

	public abstract void setValue(String key, String value);

	public abstract boolean containsKey(String key);

	public abstract String[] getAllKeys(String prefix);

	public abstract void remove(String key);
	
	public abstract void clear();

	public String getString(String key, String defaultValue) {
		String ret = getValue(key);
		if (ret != null)
			return ret;
		else
			return defaultValue;
	}

	public String getString(String key) {
		return getString(key, null);
	}

	public int getInt(String key, int defaultValue) {
		String retS = getValue(key);
		if (retS != null)
			return Integer.parseInt(retS);
		else
			return defaultValue;
	}

	public int getInt(String key) {
		return getInt(key, 0);
	}

	public long getLong(String key, long defaultValue) {
		String retS = getValue(key);
		if (retS != null)
			return Long.parseLong(retS);
		else
			return defaultValue;
	}

	public long getLong(String key) {
		return getLong(key, 0l);
	}

	public float getFloat(String key, float defaultValue) {
		String retS = getValue(key);
		if (retS != null)
			return Float.parseFloat(retS);
		else
			return defaultValue;
	}

	public float getFloat(String key) {
		return getFloat(key, 0f);
	}

	public double getDouble(String key, double defaultValue) {
		String retS = getValue(key);
		if (retS != null)
			return Double.parseDouble(retS);
		else
			return defaultValue;
	}

	public double getDouble(String key) {
		return getDouble(key, 0);
	}

	public boolean getBoolean(String key, boolean defaultValue) {
		String retS = getValue(key);
		if (retS != null)
			return Boolean.parseBoolean(retS);
		else
			return defaultValue;
	}

	public boolean getBoolean(String key) {
		return getBoolean(key, false);
	}

	public String[] getAllKeys() {
		return getAllKeys(null);
	}
}
